<?php
class content_model extends jqxGrid_CI_Model {

    function __construct()
    {
        parent::__construct();
        
    }
    function get($ID){
        $where=array('id'=>$ID);
        $query=$this->db->get_where("dtb_new", $where); 
        return $query->result();
    }
    function getByAlias($Alias,$any=false){
        $where["alias"]=$Alias;
        if($any===false)
            $where["delete"]=Null;
        $query=$this->db
                ->where($where)
                ->get("dtb_new"); 
        return $query->result_array();
    }
    function getByID($id,$any=false){
        $where["id"]=$id;
        if($any===false)
            $where["delete"]=Null;
        $query=$this->db
                ->where($where)
                ->get("dtb_new"); 
        return $query->result_array();
    }
    function insert($params){
        $this->db->set('insert', 'NOW()', FALSE);
        $this->db->insert("dtb_new", $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function delete($ID){
        $this->db->set('delete', 'NOW()', FALSE);
        $where=array('id'=>$ID);
        $this->db->where($where);
        $this->db->update("dtb_new"); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function retore($ID){
        $this->db->set('delete', 'NULL', FALSE);
        $where=array('id'=>$ID);
        $this->db->where($where);
        $this->db->update("dtb_new"); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function update($ID,$params){
        $this->db->set('update', 'NOW()', FALSE);
        $this->db->where('id', $ID);
        $this->db->update("dtb_new", $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function binding(){
        $strQuery="
            SELECT SQL_CALC_FOUND_ROWS `id` as ID,`category` as Category,`title` as Title,
                `alias` as Alias,`status` as Status,`insert` as 'Insert',
                `update` as 'Update',`delete` as 'Delete'
            FROM `dtb_new`
            ";
        $strWhere="
            WHERE  true
            ";
        if($_SESSION["ADP"][CCTRL]["display"]==0){
            $strWhere.=" AND `dtb_new`.`delete` IS NULL";
        }elseif($_SESSION["ADP"][CCTRL]["display"]==-1){
            $strWhere.=" AND `dtb_new`.`delete` IS NOT NULL";
        }
        $strOrderBy="Order By dtb_new.`insert` DESC ";
        $strGroupBy="";
        $config=array(
            "strQuery"=>$strQuery,
            "strWhere"=>$strWhere,
            "strOrderBy"=>$strOrderBy,
            "strGroupBy"=>$strGroupBy,
            "usingLimit"=>true,
            "fields"=>array(
                "ID"=>"`id`",
                "Category"=>"`category`",
                "Title"=>"title",
                "Alias"=>"`alias`",
                "Status"=>"`status`",
                "Insert"=>"dtb_new.`insert`",
                "Update"=>"dtb_new.`update`",
                "Delete"=>"dtb_new.`delete`",
            ),
            "datefields"=>array("Insert","Update","Delete")
        );
        $this->init($config);
        return $this->jqxBinding();
    }
}
?>
